package com.goodjia.phase1module3;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class WorkerTest {

    public static void main(String[] args) {

        Worker worker1 = new Worker("凤姐",18,20000);
        worker1.work();

        // 1.创建List集合加入三个worker类型员工对象
        List<Worker> lst = new LinkedList<>();
        lst.add(worker1);
        lst.add(new Worker("欧阳锋",60,8000));
        lst.add(new Worker("刘德华",40,30000));
        System.out.println("lst = " + lst);

        // 2.在下标1的位置加入员工张柏芝。 接着删除员工欧阳修
        System.out.println("-----------------------------------------");
        lst.add(1,new Worker("张柏芝",35,3300));
        System.out.println("lst = " + lst);
        lst.remove(new Worker("欧阳锋",60,8000));
        System.out.println("lst = " + lst);

        // 3.for遍历打印员工信息
        System.out.println("-----------------------------------------");
        for (Worker worker : lst) {
            System.out.println("员工信息是：" + worker);
        }

        // 4.用迭代器遍历集合同时每个对象调用work()方法
        System.out.println("-----------------------------------------");
        Iterator iterator = lst.iterator();
        while (iterator.hasNext()) {
            Worker worker = (Worker) iterator.next();
            worker.work();
        }

    }
}
